using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Drawing;
using System.Diagnostics;
using System.Windows.Forms;

using Janus.Windows.GridEX;

namespace Janus.NorthwindDemo2007
{
	public partial class SupplierDataForm
	{

		protected override void StartEdition()
		{
			this.SupplierControl1.UseTabBackground = true;
			this.SupplierControl1.DataSource = this.DataSet;
			if (this.EditMode == DataFormEditMode.AddNew)
			{
				this.Text = "Suppliers - New Supplier";
				this.SupplierControl1.IsAddNew = true;
			}
			else
			{
				this.Text = "Suppliers - " + ((DataRowView)CurrencyManager.Current)["CompanyName"];
				this.SupplierControl1.IsAddNew = false;
			}
			this.SupplierControl1.Select();
		}

		private bool mProductsFilled;
		private void FillProducts()
		{
			if (! mProductsFilled)
			{
				if (! this.DataRowView.IsNew)
				{
					DataTable categories = NorthwindApp.NorthwindApplication.GetProductList();
					this.jsgProducts.DropDowns["Products"].SetDataBinding(categories, "");
					this.Suppliers_ProductsTableAdapter1.FillBySupplier((int)DataRowView["SupplierID"], this.DataSet.Suppliers_Products);
				}
				this.jsgProducts.SetDataBinding(this.DataSet, "Suppliers.SuppliersSuppliers_Products");
				mProductsFilled = true;
			}
		}
		private void UiTab1_SelectedTabChanged(object sender, Janus.Windows.UI.Tab.TabEventArgs e)
		{
			if (e.Page == this.tabProducts)
			{
				this.FillProducts();
			}
		}

		private void jsgProducts_CellUpdated(object sender, Windows.GridEX.ColumnActionEventArgs e)
		{
			if (e.Column.Key == "ProductID" || e.Column.Key == "ProductName")
			{
				//Set the value to the other column bound to "ProductID"
				jsgProducts.SetValue("ProductID", jsgProducts.GetValue(e.Column));
				jsgProducts.SetValue("ProductName", jsgProducts.GetValue(e.Column));
			}
		}


	}

} //end of root namespace